#!/bin/sh
###################
source /etc/profile
source /root/.bash_profile
##################
cd `dirname $0`


COLLEG="
basic_semester_info.sh
base_department_major_class_info.sh
base_teacher_department_info.sh
"
COURSE="
base_course_info.sh
"
MAJOR="
base_major_info.sh
"
TEACHER="
base_teacher_info.sh
"
STUDENT="
base_student_info.sh
"

#日志路径
function getRunLogPath(){
    datetime=$(date --date "0 days ago" +%Y%m%d)
    if [ ! -d "./logs" ];then
        mkdir ./logs
    fi
     LOG_RUN_PATH=/root/etl/SXNYZY/Timing/quality/logs/$0_${datetime}.log
}


function doconmand(){
    start=$(date +%s)
    #读取文件的每一行
	for comand in ${comands}
	do
		ps -ef|grep $comand|grep -v grep|cut -c 9-15|xargs kill -9
	    sh $comand
	    end=$(date +%s)
		 if [ $? -eq 0 ]; then
	    	echo " $comand succeed>>>  耗时$(( $end - $start ))s " >>  ${LOG_RUN_PATH} 2>&1
		 else
		    echo " $comand failed>>>  耗时$(( $end - $start ))s "  >>  ${LOG_RUN_PATH} 2>&1;
		    echo " ## sh $comand 脚本执行错误，退出命令  exit 1  ##"  >>  ${LOG_RUN_PATH} 2>&1;
		    exit 1;
		 fi

	done
	end=$(date +%s)
	echo " 耗时$(( $end - $start ))s" >>  ${LOG_RUN_PATH} 2>&1
	#删除脚本执行过程中产生的Java文件
	rm -rf *.java
}


#学院层面_model
function COLLEGE() {
   echo "-------学院层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1;
   comands=${COLLEG[*]}
   doconmand
}
#课程层面_model
function COURSE() {
   echo "-------课程层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1;
   comands=${COURSE[*]}
   doconmand
}

#专业层面
function MAJOR() {
   echo "-------专业层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1;
   comands=${MAJOR[*]}
   doconmand

}
#教师层面
function TEACHER() {
   echo "-------教师层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1;
   comands=${TEACHER[*]}
   doconmand

}
#学生层面
function STUDENT() {
   echo "-------学生层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1;
   comands=${STUDENT[*]}
   doconmand

}


getRunLogPath
CURRENTPATH_COLLEGE=/root/etl/SXNYZY/diagnosis
comands=()

if [ $? -eq 0 ]; then
	cd  ${CURRENTPATH_COLLEGE}/college/model/
	COLLEGE
fi
if [ $? -eq 0 ]; then
	cd  ${CURRENTPATH_COLLEGE}/course/model/
	COURSE
fi

if [ $? -eq 0 ]; then
	cd  ${CURRENTPATH_COLLEGE}/major/model/
	MAJOR
fi

if [ $? -eq 0 ]; then
	cd  ${CURRENTPATH_COLLEGE}/teacher/model/
	TEACHER
fi

if [ $? -eq 0 ]; then
	cd  ${CURRENTPATH_COLLEGE}/student/model/
	STUDENT
fi



echo "*********所有脚本执行完毕*********" >>  ${LOG_RUN_PATH} 2>&1

